import Echarts from "./Template";
import { isProduction } from "@/configs/keys";

!isProduction && (() => import("echarts/lib/chart/bar"))();
!isProduction && (() => import("echarts/lib/component/tooltip"))();
!isProduction && (() => import("echarts/lib/component/title"))();

const filterOptions = (options) => {
  const filterOptions = {};

  Object.keys(options).forEach((optKey) => {
    if (optKey === "series") {
      filterOptions[optKey] = options[optKey].map((item) => {
        item.type = "bar";
        return item;
      });
    } else filterOptions[optKey] = options[optKey];
  });

  return filterOptions;
};

class Bar extends Echarts {
  /**
   * @constructor init echarts
   * @description 初始化echart配置
   * @param {import('echarts').EChartsCoreOption} options
   */
  constructor(options, rootElement) {
    super(filterOptions(options), rootElement);
    console.log(options);
  }
}

export default Bar;
